import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
import locale from 'element-ui/lib/locale/lang/en';
import store from './store'
import { Message } from 'element-ui';

Vue.use(ElementUI,{locale})
Vue.config.productionTip = false
Vue.directive('focus', function (el) {
  el.focus()
})
router.beforeEach((to,from,next)=>{
  next()
  if(to.meta.requireAuth){
    if(store.state.user.id != null){
      next()
    }else{
      Message({
        showClose: true,
        message: '未登录或用户身份失效，请先登录',
        type: 'warning',
        duration:1500
      });
      next({
        path:'login',
        query:{redirect: to.fullPath}
      })
    }
  }else{
    next(false)
  }
}
)
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
